package com.xintonghua.bussiness.ui.user.manage;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.EditText;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;
import com.xintonghua.bussiness.BuildConfig;
import com.xintonghua.bussiness.R;
import com.xintonghua.bussiness.base.BaseActivity;
import com.xintonghua.bussiness.bean.StaffManagerBean;
import com.xintonghua.bussiness.bean.TaskTimeBean;
import com.xintonghua.bussiness.util.MyState;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 作者：wanxianyi
 * 时间：2018/4/2.
 * 包名：com.xintonghua.bussiness.ui.user.manage
 */

public class TaskSetActivity extends BaseActivity {
    StaffManagerBean bean;
    @BindView(R.id.tv_task_time_1)
    TextView tvTaskTime1;
    @BindView(R.id.tv_task_money_1)
    EditText tvTaskMoney1;
    @BindView(R.id.tv_task_time_2)
    TextView tvTaskTime2;
    @BindView(R.id.tv_task_money_2)
    EditText tvTaskMoney2;
    @BindView(R.id.tv_task_time_3)
    TextView tvTaskTime3;
    @BindView(R.id.tv_task_money_3)
    EditText tvTaskMoney3;
    @BindView(R.id.tv_sure)
    TextView tvSure;
    List<TaskTimeBean> list;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_set_task);
        ButterKnife.bind(this);
        onSimpleActionBar();
        setSimpleActionBar("设置目标");
        bean = getIntent().getParcelableExtra(BuildConfig.FLAVOR);
        httpCent.getNextThreeMonth(this, MyState.requestOne);
    }

    @Override
    public void dataBack(Object data, int order) {
        super.dataBack(data, order);
        switch (order) {
            case MyState.requestOne:
                list = JSONObject.parseArray((String) data, TaskTimeBean.class);
                tvTaskTime1.setText(list.get(0).getMonth());
                tvTaskTime2.setText(list.get(1).getMonth());
                tvTaskTime3.setText(list.get(2).getMonth());
                break;
            case MyState.requestTwo:
                mToast("设置成功！");
                finish();
                break;
        }
    }

    @OnClick(R.id.tv_sure)
    public void onViewClicked() {
        if (TextUtils.isEmpty(getStr(tvTaskMoney1)) || TextUtils.isEmpty(getStr(tvTaskMoney2)) || TextUtils.isEmpty(getStr(tvTaskMoney3))) {
            mToast("请输入金额");
            return;
        }
        list.get(0).setMoney(Double.valueOf(getStr(tvTaskMoney1)));
        list.get(1).setMoney(Double.valueOf(getStr(tvTaskMoney2)));
        list.get(2).setMoney(Double.valueOf(getStr(tvTaskMoney3)));
        list.get(0).setTimeStr(list.get(0).getMonth());
        list.get(1).setTimeStr(list.get(1).getMonth());
        list.get(2).setTimeStr(list.get(2).getMonth());
        httpCent.shopUserTaskSave(bean.getId() + "", JSONObject.toJSON(list).toString(), this, MyState.requestTwo);

    }
}
